 <@>layout("/common/default.html"){
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">首页</a>
        <span lay-separator="">/</span>
        <a href="">系统管理</a>
        <span lay-separator="">/</span>
        <a><cite>任务管理</cite></a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i>
    </a>
</div>
<div class="x-body">
    <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
            <button class="layui-btn" onclick="x_admin_show('添加任务', '${ctxPath}/system/job/add', 600, 300)">
                <i class="layui-icon"></i>添加
            </button>
            <button class="layui-btn" onclick="doSearch();">
                刷新
            </button>
        </div>
    </div>
    <div class="layui-row layui-col-space15">
        <table class="layui-table"
               lay-data="{id:'job-list', url:'${ctxPath}/ajax/system/job/list', page:true,request: {pageName: 'page' ,limitName: 'rows'} }"
               lay-filter="job-list">
            <thead>
            <tr>
                <th lay-data="{field:'index', width:80, templet: '#table-index'}">序号</th>
                <th lay-data="{field:'jobName', width:250, sort:true}">任务名称</th>
                <th lay-data="{field:'jobGroup', width:100}">任务所在组</th>
                <th lay-data="{field:'jobClassName', width:250}">任务类名</th>
                <th lay-data="{field:'triggerName', width:250}">触发器名称</th>
                <th lay-data="{field:'triggerGroup', width:100}">触发器所在组</th>
                <th lay-data="{field:'cronExpression', width:150}">表达式</th>
                <th lay-data="{field:'timeZoneId', width:120}">时区</th>
                <th lay-data="{field:'state', width:80, templet: '#job-state'}">状态</th>
                <th lay-data="{field:'jobName', toolbar: '#toolbar',fixed:'right',width:200}">操作</th>
            </tr>
            </thead>
        </table>
    </div>

    <script type="text/html" id="toolbar">
        {{#  if(d.state == 'PAUSED'){ }}
        <a class="layui-btn layui-btn-xs" lay-event="resume">恢复</a>
        {{#  } }}
        {{#  if(d.state == 'ACQUIRED'){ }}
        <a class="layui-btn layui-btn-xs" lay-event="pause">暂停</a>
        {{#  } }}
        <a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>
        <a class="layui-btn layui-btn-xs" lay-event="update">修改</a>
    </script>

    <script type="text/html" id="job-state">
        {{#  if(d.state == 'PAUSED'){ }}
        <span class="layui-badge">暂停</span>
        {{#  } }}
        {{#  if(d.state == 'WAITING'){ }}
        <span class="layui-badge">等待</span>
        {{#  } }}
        {{#  if(d.state == 'WARNING'){ }}
        <span class="layui-badge">警告</span>
        {{#  } }}
        {{#  if(d.state == 'ACQUIRED'){ }}
        <span class="layui-badge layui-bg-green">运行</span>
        {{#  } }}
    </script>

    <script type="text/html" id="table-index">
        {{d.LAY_TABLE_INDEX + 1}}
    </script>
</div>
<script>
    $(function () {
        layui.use('table', function () {
            var url = '${ctxPath}/ajax/system/job';
            var table = layui.table;
            table.on('tool(job-list)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）

                //暂停
                if (layEvent === 'pause') {
                    layer.confirm('确定暂停任务【' + data.jobName + '】', function () {
                        //向服务端发送删除指令
                        $.cajax(url + '/pause', {
                            'jobName': data.jobName,
                            'jobGroup': data.jobGroup,
                        }, function (r) {
                            var code = r.code;
                            var msg = r.msg;
                            if (code == '1') {
                                $.msg(msg, function () {
                                    doSearch();
                                });
                            } else {
                                $.msg(msg, function () {
                                }, 2);
                            }
                        })
                    });
                }

                //恢复
                if (layEvent === 'resume') {
                    layer.confirm('确定恢复任务【' + data.jobName + '】', function () {
                        //向服务端发送删除指令
                        $.cajax(url + '/resume', {
                            'jobName': data.jobName,
                            'jobGroup': data.jobGroup,
                        }, function (r) {
                            var code = r.code;
                            var msg = r.msg;
                            if (code == '1') {
                                $.msg(msg, function () {
                                    doSearch();
                                });
                            } else {
                                $.msg(msg, function () {
                                }, 2);
                            }
                        })
                    });
                }

                //删除
                if (layEvent === 'delete') {
                    layer.confirm('确定删除任务【' + data.jobName + '】【' + data.jobGroup + '】', function () {
                        //向服务端发送删除指令
                        $.cajax(url + '/delete', {
                            'jobName': data.jobName,
                            'jobGroup': data.jobGroup,
                        }, function (r) {
                            var code = r.code;
                            var msg = r.msg;
                            if (code == '1') {
                                $.msg(msg, function () {
                                    doSearch();
                                });
                            } else {
                                $.msg(msg, function () {
                                }, 2);
                            }
                        })
                    });
                }
                if (layEvent === 'update') {//编辑
                    x_admin_show('修改任务', '${ctxPath}/system/job/edit?jobName=' + data.jobName + '&jobGroup=' + data.jobGroup + '&cronExpression=' + data.cronExpression, 600, 300)
                }
            });
        });
    });

    //搜索
    function doSearch() {
        layui.use('table', function () {
            var table = layui.table;
            table.reload('job-list', {
                url: '${ctxPath}/ajax/system/job/list',
                where: {}//设定异步数据接口的额外参数
            });
        });
    }
</script>
<@>}